import { ref } from 'vue'
import { defineStore } from 'pinia'
// import { userGetInfoService } from '@/api/user.js'

// 用户模块 token setToken removeToken
export const useUserStore = defineStore('pyg-user', () => {
  const token = ref('')
  // 存储token
  const setToken = (newToken) => {
    token.value = newToken
  }
  // 清除token
  const removeToken = () => {
    token.value = ''
  }
  // 用户信息
  const user = ref({})
  /*const getUser = async () => {
    const res = await userGetInfoService() // 请求获取数据
    user.value = res.data.data
  }*/
  const getUser = (newUser) => {
    user.value = newUser
  }
  const setUser = (obj) => {
    user.value = obj
  }

  return { token, setToken, removeToken, user, getUser, setUser }
}, {
  persist: true // 开启当前模块的持久化
})
